// #include "CH58x_common.h"
#include "74hc595.h"
#include "relay.h"
#include "tim.h"
#include "uartapp.h"

static uint8_t RelayDate[4]={0};
static uint8_t Relay_Status[16]={0};
/*********************
��������HC595Delay
���ܣ�ʵ��us����ʱ
�βΣ�cnt--usֵ
����ֵ����
��ע��
*/
void HC595Delay(uint16_t cnt)
{
    // while(cnt--)
    //     continue;
    DelayUs(cnt);
}


/*********************
��������HC595_GPIO_Init
���ܣ�595IO��ʼ��
�βΣ���
����ֵ����
��ע��
*/
void HC595_GPIO_Init(void)
{
    GPIOB_ModeCfg( SCK_595_PIN, GPIO_ModeOut_PP_20mA );
    GPIOB_ModeCfg( CLR_595_PIN, GPIO_ModeOut_PP_20mA );
    GPIOB_ModeCfg( RCK_595_PIN, GPIO_ModeOut_PP_20mA );
    GPIOB_ModeCfg( OE_595_PIN, GPIO_ModeOut_PP_20mA );
    GPIOB_ModeCfg( DATE_595_PIN, GPIO_ModeOut_PP_20mA );
    GPIOB_ResetBits(OE_595_PIN); //OEĬ��Ϊ�͵�ƽ
    GPIOB_SetBits(SCK_595_PIN); //�����Ǹ߻��ǵ�
    GPIOB_SetBits(RCK_595_PIN);
    GPIOB_SetBits(CLR_595_PIN);
    GPIOB_SetBits(DATE_595_PIN);
}

/***
 *74HC595 ����dateout����Ϊ1 
*/
void HC595_Data_High(void)
{
    GPIOB_SetBits(DATE_595_PIN);
}

/***
 *74HC595 ����dateout����Ϊ0
*/
void HC595_Data_Low(void)
{
    GPIOB_ResetBits(DATE_595_PIN);
}

/***
 *74HC595 ����SCK����Ϊ1 
*/
void HC595_SHCP_High(void)
{
    GPIOB_SetBits(SCK_595_PIN);
}

/***
 *74HC595 ����SCK����Ϊ0
*/
void HC595_SHCP_Low(void)
{
    GPIOB_ResetBits(SCK_595_PIN);
}

/***
 *74HC595 ����SCK����Ϊ1 
*/
void HC595_STCP_High(void)
{
    GPIOB_SetBits(RCK_595_PIN);
}

/***
 *74HC595 ����SCK����Ϊ0
*/
void HC595_STCP_Low(void)
{
    GPIOB_ResetBits(RCK_595_PIN);
}



/***
 *74HC595 ����һ���ֽ� 
 *����74HC595��DS���ŷ���һ���ֽ�
*/
void HC595_Send_Byte(uint8_t byte)
{
	uint8_t i;
	for (i = 0; i < 8; i ++)  //һ���ֽ�8λ������8�Σ�һ��һλ��ѭ��8�Σ��պ�����8λ
	{
	  /****  ����1�������ݴ���DS����    ****/
		if (byte & 0x80)        //�ȴ����λ��ͨ���������жϵڰ��Ƿ�Ϊ1
			HC595_Data_High();    //����ڰ�λ��1������ 595 DS���ӵ���������ߵ�ƽ
		else                    //��������͵�ƽ
			HC595_Data_Low();
		
		/*** ����2��SHCPÿ����һ�������أ���ǰ��bit�ͱ�������λ�Ĵ��� ***/
		HC595_SHCP_Low();   // SHCP����
		DelayUs(1);           // �ʵ���ʱ
		HC595_SHCP_High();  // SHCP���ߣ� SHCP����������
		// DelayUs(1);
		
		byte <<= 1;		// ����һλ������λ����λ�ƣ�ͨ��	if (byte & 0x80)�жϵ�λ�Ƿ�Ϊ1
	}
}

// void HC595_Send_Byte(uint8_t dat1)
// {

// }

/**
 *74HC595������� ʹ�� 
**/
void HC595_CS(void) 
{
	/**  ����3��STCP����һ�������أ���λ�Ĵ�������������洢�Ĵ���  **/
	HC595_STCP_Low();   // ��STCP����
	DelayUs(1);           // �ʵ���ʱ
	HC595_STCP_High();  // �ٽ�STCP���ߣ�STCP���ɲ���һ��������
	// DelayUs(1);
}
 
/**
 *���Ͷ���ֽ�
 *���ڼ���ʱ���ݵķ���
 *����N��������Ҫ����N���ֽڿ���HC595
***/
void HC595_Send_Multi_Byte(uint8_t *data, uint16_t len)
{
	uint8_t i;
    	for (i = 0; i < len; i ++ ) // len ���ֽ�
	{
		HC595_Send_Byte(data[i]);
	}
	
	HC595_CS(); //�Ȱ������ֽڷ����꣬��ʹ�����
}


void SetRelay_Date_Open(uint8_t *iDate,uint8_t Len,uint8_t CardType)
{
    uint8_t i=0;
    uint8_t LenTmp=0;

    // RelayDate[1]=0;
    // RelayDate[2]=0;
    // PRINT("iDate %0d\r\n",iDate[0]);
    LenTmp=Len;
    if(Get_Self_Count()!=0xFF)
    {
        switch (iDate[0])
        {
            case FLOOR_1:
                RelayDate[1]=RelayDate[1]&0xFE;
                RelayDate[3]=RelayDate[3]&0xFE;
            break;
            case FLOOR_2:
                RelayDate[1]=RelayDate[1]&0xFD;
                RelayDate[3]=RelayDate[3]&0xFD;
            break;
            case FLOOR_3:
                RelayDate[1]=RelayDate[1]&0xFB;
                RelayDate[3]=RelayDate[3]&0xFB;
            break;
            case FLOOR_4:
                RelayDate[1]=RelayDate[1]&0xF7;
                RelayDate[3]=RelayDate[3]&0xF7;
            break;
            case FLOOR_5:
                RelayDate[1]=RelayDate[1]&0xEF;
                RelayDate[3]=RelayDate[3]&0xEF;
            break;
            case FLOOR_6:
                RelayDate[1]=RelayDate[1]&0xDF;
                RelayDate[3]=RelayDate[3]&0xDF;
            break;
            case FLOOR_7:
                RelayDate[1]=RelayDate[1]&0xBF;
                RelayDate[3]=RelayDate[3]&0xBF;
            break;
            case FLOOR_8:
                RelayDate[1]=RelayDate[1]&0x7F;
                RelayDate[3]=RelayDate[3]&0x7F;
            break;
#ifdef LAYER_NUM_16
            case FLOOR_9:
                RelayDate[0]=RelayDate[0]&0xFE;
                RelayDate[2]=RelayDate[2]&0xFE;
            break;
            case FLOOR_10:
                RelayDate[0]=RelayDate[0]&0xFD;;
                RelayDate[2]=RelayDate[2]&0xFD;

            break;
            case FLOOR_11:
                RelayDate[0]=RelayDate[0]&0xFB;
                RelayDate[2]=RelayDate[2]&0xFB;
            break;
            case FLOOR_12:
                RelayDate[0]=RelayDate[0]&0xF7;
                RelayDate[2]=RelayDate[2]&0xF7;
            break;
            case FLOOR_13:
                RelayDate[0]=RelayDate[0]&0xEF;
                RelayDate[2]=RelayDate[2]&0xEF;
            break;
            case FLOOR_14:
                RelayDate[0]=RelayDate[0]&0xDF;
                RelayDate[2]=RelayDate[2]&0xDF;
            break;
            case FLOOR_15:
                RelayDate[0]=RelayDate[0]&0xBF;
                RelayDate[2]=RelayDate[2]&0xBF;
            break;
            case FLOOR_16:
                RelayDate[0]=RelayDate[0]&0x7F;
                RelayDate[2]=RelayDate[2]&0x7F;
            break;
#endif
            default:
            break;
        }
        HC595_Send_Multi_Byte(RelayDate,4);
        return;
    }
    else 
    {
         PRINT("Len %0d\r\n",Len);
        if(Get_Other_Floor_Fg()==0x11)
        {
            uint8_t PublicLen=0;
            uint8_t j=0,k=0;
            uint8_t Public_Floor_Temp[16];
            uint8_t PublicFoundFg=0;
            PublicLen=Get_PublicFloor(Public_Floor_Temp);
            // if((Len==1)&&(Get_Other_Floor_Fg()==0))
            PRINT("Len %0d\r\n",Len);
            for(j=0;j<PublicLen;j++)
            {  
                if(Len==0)
                {
                    Len=PublicLen;
                }
                {
                    // PRINT("Public_Floor_Temp %02x iDate %02x CardType %0d\r\n",Public_Floor_Temp[j],iDate[i],CardType);
                    if(CardType==0x02)
                    {
                        for(k=0;k<Len;k++)
                        {
                            PRINT("11111111111Public_Floor_Temp[%0d ] %02x k %0d \r\n",j,Public_Floor_Temp[j],iDate[k]);
                            if(Public_Floor_Temp[j]==iDate[k]) //����¥��ֱ��
                            {
                                // PublicFoundFg=1;
                                PRINT("Public_Floor_Temp[%0d ] %02x k %0d \r\n",j,Public_Floor_Temp[j],iDate[k]);
                                switch (iDate[k])
                                {
                                    case FLOOR_1:
                                        if(Relay_Status[0]==0)
                                        {
                                            Relay_Status[0]=1;
                                            RelayDate[1]=RelayDate[1]|0x01;
                                            RelayDate[3]=RelayDate[3]&0xFE;
                                            Set_LayerDirectTimeCount(FLOOR_1);
                                            PRINT("1\r\n");
                                        }
                                    break;
                                    case FLOOR_2:
                                        if(Relay_Status[1]==0)
                                        {
                                            Relay_Status[1]=1;
                                            RelayDate[1]=RelayDate[1]|0x02;
                                            RelayDate[3]=RelayDate[3]&0xFD;
                                            Set_LayerDirectTimeCount(FLOOR_2);
                                        }
                                    break;
                                    case FLOOR_3:
                                        if(Relay_Status[2]==0)
                                        {
                                            Relay_Status[2]=1;
                                            RelayDate[1]=RelayDate[1]|0x04;
                                            RelayDate[3]=RelayDate[3]&0xFB;
                                            Set_LayerDirectTimeCount(FLOOR_3);
                                        }
                                    break;
                                    case FLOOR_4:
                                        if(Relay_Status[3]==0)
                                        {
                                            Relay_Status[3]=1;
                                            RelayDate[1]=RelayDate[1]|0x08;
                                            RelayDate[3]=RelayDate[3]&0xF7;
                                            Set_LayerDirectTimeCount(FLOOR_4);
                                            PRINT("333333\r\n");
                                        }
                                    break;
                                    case FLOOR_5:
                                        if(Relay_Status[4]==0)
                                        {
                                            Relay_Status[4]=1;
                                            RelayDate[1]=RelayDate[1]|0x10;
                                            RelayDate[3]=RelayDate[3]&0xEF;
                                            Set_LayerDirectTimeCount(FLOOR_5);
                                            PRINT("111111111\r\n");
                                        }
                                    break;
                                    case FLOOR_6:
                                        if(Relay_Status[5]==0)
                                        {
                                            Relay_Status[5]=1;
                                            RelayDate[1]=RelayDate[1]|0x20;
                                            RelayDate[3]=RelayDate[3]&0xDF;
                                            Set_LayerDirectTimeCount(FLOOR_6);
                                            PRINT("222222\r\n");
                                        }
                                    break;
                                    case FLOOR_7:
                                        if(Relay_Status[6]==0)
                                        {
                                            Relay_Status[6]=1;
                                            RelayDate[1]=RelayDate[1]|0x40;
                                            RelayDate[3]=RelayDate[3]&0xBF;
                                            Set_LayerDirectTimeCount(FLOOR_7);
                                        }
                                    break;
                                    case FLOOR_8:
                                        if(Relay_Status[7]==0)
                                        {
                                            Relay_Status[7]=1;
                                            RelayDate[1]=RelayDate[1]|0x80;//&0x7F;
                                            RelayDate[3]=RelayDate[3]&0x7F;
                                            Set_LayerDirectTimeCount(FLOOR_8);
                                        }
                                    break;
                                    case FLOOR_9:
                                        if(Relay_Status[8]==0)
                                        {
                                            Relay_Status[8]=1;
                                            RelayDate[0]=RelayDate[0]|0x01;
                                            RelayDate[2]=RelayDate[2]&0xFE;
                                            Set_LayerDirectTimeCount(FLOOR_9);
                                        }
                                    break;
                                    case FLOOR_10:
                                        if(Relay_Status[9]==0)
                                        {
                                            Relay_Status[9]=1;
                                            RelayDate[0]=RelayDate[0]|0x02;;
                                            RelayDate[2]=RelayDate[2]&0xFD;
                                            Set_LayerDirectTimeCount(FLOOR_10);
                                        }
                                    break;
                                    case FLOOR_11:
                                        if(Relay_Status[10]==0)
                                        {
                                            Relay_Status[10]=1;
                                            RelayDate[0]=RelayDate[0]|0x04;
                                            RelayDate[2]=RelayDate[2]&0xFB;
                                            Set_LayerDirectTimeCount(FLOOR_11);
                                        }
                                    break;
                                    case FLOOR_12:
                                        if(Relay_Status[11]==0)
                                        {
                                            Relay_Status[11]=1;
                                            RelayDate[0]=RelayDate[0]|0x08;
                                            RelayDate[2]=RelayDate[2]&0xF7;
                                            Set_LayerDirectTimeCount(FLOOR_12);
                                        }
                                    break;
                                    case FLOOR_13:
                                        if(Relay_Status[12]==0)
                                        {
                                            Relay_Status[12]=1;
                                            RelayDate[0]=RelayDate[0]|0x10;
                                            RelayDate[2]=RelayDate[2]&0xEF;
                                            Set_LayerDirectTimeCount(FLOOR_13);
                                        }
                                    break;
                                    case FLOOR_14:
                                        if(Relay_Status[13]==0)
                                        {
                                            Relay_Status[13]=1;
                                            RelayDate[0]=RelayDate[0]|0x20;
                                            RelayDate[2]=RelayDate[2]&0xDF;
                                            Set_LayerDirectTimeCount(FLOOR_14);
                                        }
                                    break;
                                    case FLOOR_15:
                                        if(Relay_Status[14]==0)
                                        {
                                            Relay_Status[14]=1;
                                            RelayDate[0]=RelayDate[0]|0x40;
                                            RelayDate[2]=RelayDate[2]&0xBF;
                                            Set_LayerDirectTimeCount(FLOOR_15);
                                        }
                                    break;
                                    case FLOOR_16:
                                        if(Relay_Status[15]==0)
                                        {
                                            Relay_Status[15]=1;
                                            RelayDate[0]=RelayDate[0]|0x80;
                                            RelayDate[2]=RelayDate[2]&0x7F;
                                            Set_LayerDirectTimeCount(FLOOR_16);
                                        }
                                    break;
                                    default:
                                    break;
                                }
                                iDate[k]=0xFF;
                                // break;
                            }
                            else  //�Ǳ��Ϳ�����¥���밴��
                            {
                                PRINT("iDate111111 %02x j %0d \r\n",Public_Floor_Temp[j],j);
                                switch (Public_Floor_Temp[j])
                                {
                                    case FLOOR_1:
                                        RelayDate[3]=RelayDate[3]&0xFE;
                                        Set_LayerTimeCount(FLOOR_1);
                                    break;
                                    case FLOOR_2:
                                        RelayDate[3]=RelayDate[3]&0xFD;
                                        Set_LayerTimeCount(FLOOR_2);
                                    break;
                                    case FLOOR_3:
                                        RelayDate[3]=RelayDate[3]&0xFB;
                                        Set_LayerTimeCount(FLOOR_3);
                                    break;
                                    case FLOOR_4:
                                        RelayDate[3]=RelayDate[3]&0xF7;
                                        Set_LayerTimeCount(FLOOR_4);
                                    break;
                                    case FLOOR_5:
                                        RelayDate[3]=RelayDate[3]&0xEF;
                                        Set_LayerTimeCount(FLOOR_5);
                                    break;
                                    case FLOOR_6:
                                        RelayDate[3]=RelayDate[3]&0xDF;
                                        Set_LayerTimeCount(FLOOR_6);
                                        PRINT("5  RelayDate[3] %02x\r\n",RelayDate[3]);
                                    break;
                                    case FLOOR_7:
                                        RelayDate[3]=RelayDate[3]&0xBF;
                                        Set_LayerTimeCount(FLOOR_7);
                                        PRINT("6 RelayDate[3] %02x \r\n",RelayDate[3]);
                                    break;
                                    case FLOOR_8:
                                        RelayDate[3]=RelayDate[3]&0x7F;
                                        Set_LayerTimeCount(FLOOR_8);
                                        PRINT("7\r\n");
                                    break;
        #ifdef LAYER_NUM_16
                                    case FLOOR_9:
                                        RelayDate[2]=RelayDate[2]&0xFE;
                                        Set_LayerTimeCount(FLOOR_9);
                                    break;
                                    case FLOOR_10:
                                        RelayDate[2]=RelayDate[2]&0xFD;
                                        Set_LayerTimeCount(FLOOR_10);
                                    break;
                                    case FLOOR_11:
                                        RelayDate[2]=RelayDate[2]&0xFB;
                                        Set_LayerTimeCount(FLOOR_11);
                                    break;
                                    case FLOOR_12:
                                        RelayDate[2]=RelayDate[2]&0xF7;
                                        Set_LayerTimeCount(FLOOR_12);
                                    break;
                                    case FLOOR_13:
                                        RelayDate[2]=RelayDate[2]&0xEF;
                                        Set_LayerTimeCount(FLOOR_13);
                                    break;
                                    case FLOOR_14:

                                        RelayDate[2]=RelayDate[2]&0xDF;
                                        Set_LayerTimeCount(FLOOR_14);
                                    break;
                                    case FLOOR_15:
                                        RelayDate[2]=RelayDate[2]&0xBF;
                                        Set_LayerTimeCount(FLOOR_15);
                                    break;
                                    case FLOOR_16:
                                        RelayDate[2]=RelayDate[2]&0x7F;
                                        Set_LayerTimeCount(FLOOR_16);
                                    break;
        #endif
                                    default:
                                    break;
                                }
                            }  
                        }
                        
                    }    
                    else  //�Ǳ��Ϳ�����¥���밴��
                    {
                         switch (Public_Floor_Temp[j])
                        {
                            case FLOOR_1:
                                RelayDate[3]=RelayDate[3]&0xFE;
                                Set_LayerTimeCount(FLOOR_1);
                            break;
                            case FLOOR_2:
                                RelayDate[3]=RelayDate[3]&0xFD;
                                Set_LayerTimeCount(FLOOR_2);
                            break;
                            case FLOOR_3:
                                RelayDate[3]=RelayDate[3]&0xFB;
                                Set_LayerTimeCount(FLOOR_3);
                            break;
                            case FLOOR_4:
                                RelayDate[3]=RelayDate[3]&0xF7;
                                Set_LayerTimeCount(FLOOR_4);
                            break;
                            case FLOOR_5:
                                RelayDate[3]=RelayDate[3]&0xEF;
                                Set_LayerTimeCount(FLOOR_5);
                            break;
                            case FLOOR_6:
                                RelayDate[3]=RelayDate[3]&0xDF;
                                Set_LayerTimeCount(FLOOR_6);
                                PRINT("5  RelayDate[3] %02x\r\n",RelayDate[3]);
                            break;
                            case FLOOR_7:
                                RelayDate[3]=RelayDate[3]&0xBF;
                                Set_LayerTimeCount(FLOOR_7);
                                PRINT("6 RelayDate[3] %02x \r\n",RelayDate[3]);
                            break;
                            case FLOOR_8:
                                RelayDate[3]=RelayDate[3]&0x7F;
                                Set_LayerTimeCount(FLOOR_8);
                                PRINT("7\r\n");
                            break;
#ifdef LAYER_NUM_16
                            case FLOOR_9:
                                RelayDate[2]=RelayDate[2]&0xFE;
                                Set_LayerTimeCount(FLOOR_9);
                            break;
                            case FLOOR_10:
                                RelayDate[2]=RelayDate[2]&0xFD;
                                Set_LayerTimeCount(FLOOR_10);
                            break;
                            case FLOOR_11:
                                RelayDate[2]=RelayDate[2]&0xFB;
                                Set_LayerTimeCount(FLOOR_11);
                            break;
                            case FLOOR_12:
                                RelayDate[2]=RelayDate[2]&0xF7;
                                Set_LayerTimeCount(FLOOR_12);
                            break;
                            case FLOOR_13:
                                RelayDate[2]=RelayDate[2]&0xEF;
                                Set_LayerTimeCount(FLOOR_13);
                            break;
                            case FLOOR_14:

                                RelayDate[2]=RelayDate[2]&0xDF;
                                Set_LayerTimeCount(FLOOR_14);
                            break;
                            case FLOOR_15:
                                RelayDate[2]=RelayDate[2]&0xBF;
                                Set_LayerTimeCount(FLOOR_15);
                            break;
                            case FLOOR_16:
                                RelayDate[2]=RelayDate[2]&0x7F;
                                Set_LayerTimeCount(FLOOR_16);
                            break;
#endif
                            default:
                            break;
                        }
                    }
                }
            }
            Len=LenTmp;
            for(i=0;i<Len;i++)
            {
                // PRINT("Public_Floor_Temp %02x iDate %02x\r\n",Public_Floor_Temp[j],iDate[i]);
                if(CardType==0x02) //���Ϳ�ȫֱ��
                {
                    PRINT("i %02x iDate %02x\r\n",i,iDate[i]);
                    switch (iDate[i])
                    {
                        case FLOOR_1:
                            if(Relay_Status[0]==0)
                            {
                                Relay_Status[0]=1;
                                RelayDate[1]=RelayDate[1]|0x01;
                                RelayDate[3]=RelayDate[3]&0xFE;
                                Set_LayerDirectTimeCount(FLOOR_1);
                                PRINT("1\r\n");
                            }
                        break;
                        case FLOOR_2:
                            if(Relay_Status[1]==0)
                            {
                                Relay_Status[1]=1;
                                RelayDate[1]=RelayDate[1]|0x02;
                                RelayDate[3]=RelayDate[3]&0xFD;
                                Set_LayerDirectTimeCount(FLOOR_2);
                            }
                        break;
                        case FLOOR_3:
                            if(Relay_Status[2]==0)
                            {
                                Relay_Status[2]=1;
                                RelayDate[1]=RelayDate[1]|0x04;
                                RelayDate[3]=RelayDate[3]&0xFB;
                                Set_LayerDirectTimeCount(FLOOR_3);
                            }
                        break;
                        case FLOOR_4:
                            if(Relay_Status[3]==0)
                            {
                                Relay_Status[3]=1;
                                RelayDate[1]=RelayDate[1]|0x08;
                                RelayDate[3]=RelayDate[3]&0xF7;
                                Set_LayerDirectTimeCount(FLOOR_4);
                                PRINT("333333\r\n");
                            }
                        break;
                        case FLOOR_5:
                            if(Relay_Status[4]==0)
                            {
                                Relay_Status[4]=1;
                                RelayDate[1]=RelayDate[1]|0x10;
                                RelayDate[3]=RelayDate[3]&0xEF;
                                Set_LayerDirectTimeCount(FLOOR_5);
                                PRINT("111111111\r\n");
                            }
                        break;
                        case FLOOR_6:
                            if(Relay_Status[5]==0)
                            {
                                Relay_Status[5]=1;
                                RelayDate[1]=RelayDate[1]|0x20;
                                RelayDate[3]=RelayDate[3]&0xDF;
                                Set_LayerDirectTimeCount(FLOOR_6);
                                PRINT("222222\r\n");
                            }
                        break;
                        case FLOOR_7:
                            if(Relay_Status[6]==0)
                            {
                                Relay_Status[6]=1;
                                RelayDate[1]=RelayDate[1]|0x40;
                                RelayDate[3]=RelayDate[3]&0xBF;
                                Set_LayerDirectTimeCount(FLOOR_7);
                            }
                        break;
                        case FLOOR_8:
                            if(Relay_Status[7]==0)
                            {
                                Relay_Status[7]=1;
                                RelayDate[1]=RelayDate[1]|0x80;//&0x7F;
                                RelayDate[3]=RelayDate[3]&0x7F;
                                Set_LayerDirectTimeCount(FLOOR_8);
                            }
                        break;
                        case FLOOR_9:
                            if(Relay_Status[8]==0)
                            {
                                Relay_Status[8]=1;
                                RelayDate[0]=RelayDate[0]|0x01;
                                RelayDate[2]=RelayDate[2]&0xFE;
                                Set_LayerDirectTimeCount(FLOOR_9);
                            }
                        break;
                        case FLOOR_10:
                            if(Relay_Status[9]==0)
                            {
                                Relay_Status[9]=1;
                                RelayDate[0]=RelayDate[0]|0x02;;
                                RelayDate[2]=RelayDate[2]&0xFD;
                                Set_LayerDirectTimeCount(FLOOR_10);
                            }
                        break;
                        case FLOOR_11:
                            if(Relay_Status[10]==0)
                            {
                                Relay_Status[10]=1;
                                RelayDate[0]=RelayDate[0]|0x04;
                                RelayDate[2]=RelayDate[2]&0xFB;
                                Set_LayerDirectTimeCount(FLOOR_11);
                            }
                        break;
                        case FLOOR_12:
                            if(Relay_Status[11]==0)
                            {
                                Relay_Status[11]=1;
                                RelayDate[0]=RelayDate[0]|0x08;
                                RelayDate[2]=RelayDate[2]&0xF7;
                                Set_LayerDirectTimeCount(FLOOR_12);
                            }
                        break;
                        case FLOOR_13:
                            if(Relay_Status[12]==0)
                            {
                                Relay_Status[12]=1;
                                RelayDate[0]=RelayDate[0]|0x10;
                                RelayDate[2]=RelayDate[2]&0xEF;
                                Set_LayerDirectTimeCount(FLOOR_13);
                            }
                        break;
                        case FLOOR_14:
                            if(Relay_Status[13]==0)
                            {
                                Relay_Status[13]=1;
                                RelayDate[0]=RelayDate[0]|0x20;
                                RelayDate[2]=RelayDate[2]&0xDF;
                                Set_LayerDirectTimeCount(FLOOR_14);
                            }
                        break;
                        case FLOOR_15:
                            if(Relay_Status[14]==0)
                            {
                                Relay_Status[14]=1;
                                RelayDate[0]=RelayDate[0]|0x40;
                                RelayDate[2]=RelayDate[2]&0xBF;
                                Set_LayerDirectTimeCount(FLOOR_15);
                            }
                        break;
                        case FLOOR_16:
                        if(Relay_Status[15]==0)
                        {
                            Relay_Status[15]=1;
                            RelayDate[0]=RelayDate[0]|0x80;
                            RelayDate[2]=RelayDate[2]&0x7F;
                            Set_LayerDirectTimeCount(FLOOR_16);
                        }
                        break;
                        default:
                        break;
                    }
                }
                else   //�Ǳ��Ϳ��밴��
                {
                    // for(i=0;i<Len;i++)
                    {
                        switch (iDate[i])
                        {
                            case FLOOR_1:
                                RelayDate[3]=RelayDate[3]&0xFE;
                                Set_LayerTimeCount(FLOOR_1);
                            break;
                            case FLOOR_2:
                                RelayDate[3]=RelayDate[3]&0xFD;
                                Set_LayerTimeCount(FLOOR_2);
                            break;
                            case FLOOR_3:
                                RelayDate[3]=RelayDate[3]&0xFB;
                                Set_LayerTimeCount(FLOOR_3);
                            break;
                            case FLOOR_4:
                                RelayDate[3]=RelayDate[3]&0xF7;
                                Set_LayerTimeCount(FLOOR_4);
                            break;
                            case FLOOR_5:
                                RelayDate[3]=RelayDate[3]&0xEF;
                                Set_LayerTimeCount(FLOOR_5);
                            break;
                            case FLOOR_6:
                                RelayDate[3]=RelayDate[3]&0xDF;
                                Set_LayerTimeCount(FLOOR_6);
                                PRINT("5  RelayDate[3] %02x\r\n",RelayDate[3]);
                            break;
                            case FLOOR_7:
                                RelayDate[3]=RelayDate[3]&0xBF;
                                Set_LayerTimeCount(FLOOR_7);
                                PRINT("6 RelayDate[3] %02x \r\n",RelayDate[3]);
                            break;
                            case FLOOR_8:
                                RelayDate[3]=RelayDate[3]&0x7F;
                                Set_LayerTimeCount(FLOOR_8);
                                PRINT("7\r\n");
                            break;
#ifdef LAYER_NUM_16
                            case FLOOR_9:
                                RelayDate[2]=RelayDate[2]&0xFE;
                                Set_LayerTimeCount(FLOOR_9);
                            break;
                            case FLOOR_10:
                                RelayDate[2]=RelayDate[2]&0xFD;
                                Set_LayerTimeCount(FLOOR_10);
                            break;
                            case FLOOR_11:
                                RelayDate[2]=RelayDate[2]&0xFB;
                                Set_LayerTimeCount(FLOOR_11);
                            break;
                            case FLOOR_12:
                                RelayDate[2]=RelayDate[2]&0xF7;
                                Set_LayerTimeCount(FLOOR_12);
                            break;
                            case FLOOR_13:
                                RelayDate[2]=RelayDate[2]&0xEF;
                                Set_LayerTimeCount(FLOOR_13);
                            break;
                            case FLOOR_14:

                                RelayDate[2]=RelayDate[2]&0xDF;
                                Set_LayerTimeCount(FLOOR_14);
                            break;
                            case FLOOR_15:
                                RelayDate[2]=RelayDate[2]&0xBF;
                                Set_LayerTimeCount(FLOOR_15);
                            break;
                            case FLOOR_16:
                                RelayDate[2]=RelayDate[2]&0x7F;
                                Set_LayerTimeCount(FLOOR_16);
                            break;
#endif
                            default:
                            break;
                        }
                    }
                }
            }
            HC595_Send_Multi_Byte(RelayDate,4);
        }
        else if(Get_Other_Floor_Fg()==0x10)
        {
            if((Len==1)&&(Get_Other_Floor_Fg()==0x10))
            {
                switch (iDate[0])
                {
                    case FLOOR_1:
                        if(Relay_Status[0]==0)
                        {
                            Relay_Status[0]=1;
                            RelayDate[1]=RelayDate[1]|0x01;
                            RelayDate[3]=RelayDate[3]&0xFE;
                            Set_LayerDirectTimeCount(FLOOR_1);
                            PRINT("111111\r\n");
                        }
                    break;
                    case FLOOR_2:
                        if(Relay_Status[1]==0)
                        {
                            Relay_Status[1]=1;
                            RelayDate[1]=RelayDate[1]|0x02;
                            RelayDate[3]=RelayDate[3]&0xFD;
                            Set_LayerDirectTimeCount(FLOOR_2);
                        }
                    break;
                    case FLOOR_3:
                        if(Relay_Status[2]==0)
                        {
                            Relay_Status[2]=1;
                            RelayDate[1]=RelayDate[1]|0x04;
                            RelayDate[3]=RelayDate[3]&0xFB;
                            Set_LayerDirectTimeCount(FLOOR_3);
                        }
                    break;
                    case FLOOR_4:
                        if(Relay_Status[3]==0)
                        {
                            Relay_Status[3]=1;
                            RelayDate[1]=RelayDate[1]|0x08;
                            RelayDate[3]=RelayDate[3]&0xF7;
                            Set_LayerDirectTimeCount(FLOOR_4);
                        }
                    break;
                    case FLOOR_5:
                        if(Relay_Status[4]==0)
                        {
                            Relay_Status[4]=1;
                            RelayDate[1]=RelayDate[1]|0x10;
                            RelayDate[3]=RelayDate[3]&0xEF;
                            Set_LayerDirectTimeCount(FLOOR_5);
                        }
                    break;
                    case FLOOR_6:
                        if(Relay_Status[5]==0)
                        {
                            Relay_Status[5]=1;
                            RelayDate[1]=RelayDate[1]|0x20;
                            RelayDate[3]=RelayDate[3]&0xDF;
                            Set_LayerDirectTimeCount(FLOOR_6);
                        }
                    break;
                    case FLOOR_7:
                        if(Relay_Status[6]==0)
                        {
                            Relay_Status[6]=1;
                            RelayDate[1]=RelayDate[1]|0x40;
                            RelayDate[3]=RelayDate[3]&0xBF;
                            Set_LayerDirectTimeCount(FLOOR_7);
                        }
                    break;
                    case FLOOR_8:
                        if(Relay_Status[7]==0)
                        {
                            Relay_Status[7]=1;
                            RelayDate[1]=RelayDate[1]|0x80;//&0x7F;
                            RelayDate[3]=RelayDate[3]&0x7F;
                            PRINT("222222\r\n");
                            Set_LayerDirectTimeCount(FLOOR_8);
                        }
                    break;
 #ifdef LAYER_NUM_16
                    case FLOOR_9:
                        if(Relay_Status[8]==0)
                        {
                            Relay_Status[8]=1;
                            RelayDate[0]=RelayDate[0]|0x01;
                            RelayDate[2]=RelayDate[2]&0xFE;
                            Set_LayerDirectTimeCount(FLOOR_9);
                        }
                    break;
                    case FLOOR_10:
                        if(Relay_Status[9]==0)
                        {
                            Relay_Status[9]=1;
                            RelayDate[0]=RelayDate[0]|0x02;;
                            RelayDate[2]=RelayDate[2]&0xFD;
                            Set_LayerDirectTimeCount(FLOOR_10);
                        }
                    break;
                    case FLOOR_11:
                        if(Relay_Status[10]==0)
                        {
                            Relay_Status[10]=1;
                            RelayDate[0]=RelayDate[0]|0x04;
                            RelayDate[2]=RelayDate[2]&0xFB;
                            Set_LayerDirectTimeCount(FLOOR_11);
                        }
                    break;
                    case FLOOR_12:
                        if(Relay_Status[11]==0)
                        {
                            Relay_Status[11]=1;
                            RelayDate[0]=RelayDate[0]|0x08;
                            RelayDate[2]=RelayDate[2]&0xF7;
                            Set_LayerDirectTimeCount(FLOOR_12);
                        }
                    break;
                    case FLOOR_13:
                        if(Relay_Status[12]==0)
                        {
                            Relay_Status[12]=1;
                            RelayDate[0]=RelayDate[0]|0x10;
                            RelayDate[2]=RelayDate[2]&0xEF;
                            Set_LayerDirectTimeCount(FLOOR_13);
                        }
                    break;
                    case FLOOR_14:
                        if(Relay_Status[13]==0)
                        {
                            Relay_Status[13]=1;
                            RelayDate[0]=RelayDate[0]|0x20;
                            RelayDate[2]=RelayDate[2]&0xDF;
                            Set_LayerDirectTimeCount(FLOOR_14);
                        }
                    break;
                    case FLOOR_15:
                        if(Relay_Status[14]==0)
                        {
                            Relay_Status[14]=1;
                            RelayDate[0]=RelayDate[0]|0x40;
                            RelayDate[2]=RelayDate[2]&0xBF;
                            Set_LayerDirectTimeCount(FLOOR_15);
                        }
                    break;
                    case FLOOR_16:
                        if(Relay_Status[15]==0)
                        {
                            Relay_Status[15]=1;
                            RelayDate[0]=RelayDate[0]|0x80;
                            RelayDate[2]=RelayDate[2]&0x7F;
                            Set_LayerDirectTimeCount(FLOOR_16);
                        }
                    break;
        #endif
                    default:
                    break;
                }
                HC595_Send_Multi_Byte(RelayDate,4);
                return;
            }
            for(i=0;i<Len;i++)
            {
                switch (iDate[i])
                {
                    case FLOOR_1:
                        RelayDate[3]=RelayDate[3]&0xFE;
                        Set_LayerTimeCount(FLOOR_1);
                    break;
                    case FLOOR_2:
                        RelayDate[3]=RelayDate[3]&0xFD;
                        Set_LayerTimeCount(FLOOR_2);
                    break;
                    case FLOOR_3:
                        RelayDate[3]=RelayDate[3]&0xFB;
                        Set_LayerTimeCount(FLOOR_3);
                    break;
                    case FLOOR_4:
                        RelayDate[3]=RelayDate[3]&0xF7;
                        Set_LayerTimeCount(FLOOR_4);
                    break;
                    case FLOOR_5:
                        RelayDate[3]=RelayDate[3]&0xEF;
                        Set_LayerTimeCount(FLOOR_5);
                    break;
                    case FLOOR_6:
                        RelayDate[3]=RelayDate[3]&0xDF;
                        Set_LayerTimeCount(FLOOR_6);
                    break;
                    case FLOOR_7:
                        RelayDate[3]=RelayDate[3]&0xBF;
                        Set_LayerTimeCount(FLOOR_7);
                    break;
                    case FLOOR_8:
                        RelayDate[3]=RelayDate[3]&0x7F;
                        Set_LayerTimeCount(FLOOR_8);
                    break;
        #ifdef LAYER_NUM_16
                    case FLOOR_9:
                        RelayDate[2]=RelayDate[2]&0xFE;
                        Set_LayerTimeCount(FLOOR_9);
                    break;
                    case FLOOR_10:
                        RelayDate[2]=RelayDate[2]&0xFD;
                        Set_LayerTimeCount(FLOOR_10);
                    break;
                    case FLOOR_11:
                        RelayDate[2]=RelayDate[2]&0xFB;
                        Set_LayerTimeCount(FLOOR_11);
                    break;
                    case FLOOR_12:
                        RelayDate[2]=RelayDate[2]&0xF7;
                        Set_LayerTimeCount(FLOOR_12);
                    break;
                    case FLOOR_13:
                        RelayDate[2]=RelayDate[2]&0xEF;
                        Set_LayerTimeCount(FLOOR_13);
                    break;
                    case FLOOR_14:

                        RelayDate[2]=RelayDate[2]&0xDF;
                        Set_LayerTimeCount(FLOOR_14);
                    break;
                    case FLOOR_15:
                        RelayDate[2]=RelayDate[2]&0xBF;
                        Set_LayerTimeCount(FLOOR_15);
                    break;
                    case FLOOR_16:
                        RelayDate[2]=RelayDate[2]&0x7F;
                        Set_LayerTimeCount(FLOOR_16);
                    break;
        #endif
                    default:
                    break;
                }
            }
            HC595_Send_Multi_Byte(RelayDate,4);
        }
        else 
        {
            for(i=0;i<Len;i++)
            {
                switch (iDate[i])
                {
                    case FLOOR_1:
                        RelayDate[3]=RelayDate[3]&0xFE;
                        Set_LayerTimeCount(FLOOR_1);
                    break;
                    case FLOOR_2:
                        RelayDate[3]=RelayDate[3]&0xFD;
                        Set_LayerTimeCount(FLOOR_2);
                    break;
                    case FLOOR_3:
                        RelayDate[3]=RelayDate[3]&0xFB;
                        Set_LayerTimeCount(FLOOR_3);
                    break;
                    case FLOOR_4:
                        RelayDate[3]=RelayDate[3]&0xF7;
                        Set_LayerTimeCount(FLOOR_4);
                    break;
                    case FLOOR_5:
                        RelayDate[3]=RelayDate[3]&0xEF;
                        Set_LayerTimeCount(FLOOR_5);
                    break;
                    case FLOOR_6:
                        RelayDate[3]=RelayDate[3]&0xDF;
                        Set_LayerTimeCount(FLOOR_6);
                    break;
                    case FLOOR_7:
                        RelayDate[3]=RelayDate[3]&0xBF;
                        Set_LayerTimeCount(FLOOR_7);
                    break;
                    case FLOOR_8:
                        RelayDate[3]=RelayDate[3]&0x7F;
                        Set_LayerTimeCount(FLOOR_8);
                    break;
        #ifdef LAYER_NUM_16
                    case FLOOR_9:
                        RelayDate[2]=RelayDate[2]&0xFE;
                        Set_LayerTimeCount(FLOOR_9);
                    break;
                    case FLOOR_10:
                        RelayDate[2]=RelayDate[2]&0xFD;
                        Set_LayerTimeCount(FLOOR_10);
                    break;
                    case FLOOR_11:
                        RelayDate[2]=RelayDate[2]&0xFB;
                        Set_LayerTimeCount(FLOOR_11);
                    break;
                    case FLOOR_12:
                        RelayDate[2]=RelayDate[2]&0xF7;
                        Set_LayerTimeCount(FLOOR_12);
                    break;
                    case FLOOR_13:
                        RelayDate[2]=RelayDate[2]&0xEF;
                        Set_LayerTimeCount(FLOOR_13);
                    break;
                    case FLOOR_14:

                        RelayDate[2]=RelayDate[2]&0xDF;
                        Set_LayerTimeCount(FLOOR_14);
                    break;
                    case FLOOR_15:
                        RelayDate[2]=RelayDate[2]&0xBF;
                        Set_LayerTimeCount(FLOOR_15);
                    break;
                    case FLOOR_16:
                        RelayDate[2]=RelayDate[2]&0x7F;
                        Set_LayerTimeCount(FLOOR_16);
                    break;
        #endif
                    default:
                    break;
                }
            }
            HC595_Send_Multi_Byte(RelayDate,4);
        }
    }
        
}

void SetRelay_Date_Close(uint8_t *iDate)
{
    // uint8_t i=0;
    if(Get_Self_Count()!=0xFF)
    {
        switch (iDate[0])
        {
            case FLOOR_1:
                RelayDate[1]=RelayDate[1]|0x01;
                RelayDate[3]=RelayDate[3]|0x01;
            break;
            case FLOOR_2:
                RelayDate[1]=RelayDate[1]|0x02;
                RelayDate[3]=RelayDate[3]|0x02;
            break;
            case FLOOR_3:
                RelayDate[1]=RelayDate[1]|0x04;
                RelayDate[3]=RelayDate[3]|0x04;
            break;
            case FLOOR_4:
                RelayDate[1]=RelayDate[1]|0x08;
                RelayDate[3]=RelayDate[3]|0x08;
            break;
            case FLOOR_5:
                RelayDate[1]=RelayDate[1]|0x10;
                RelayDate[3]=RelayDate[3]|0x10; 
            break;
            case FLOOR_6:
                RelayDate[1]=RelayDate[1]|0x20;
                RelayDate[3]=RelayDate[3]|0x20;
                
            break;
            case FLOOR_7:
                RelayDate[1]=RelayDate[1]|0x40;
                RelayDate[3]=RelayDate[3]|0x40;
            break;
            case FLOOR_8:
                RelayDate[1]=RelayDate[1]|0x80;
                RelayDate[3]=RelayDate[3]|0x80;
                
            break;
    #ifdef LAYER_NUM_16
            case FLOOR_9:
                RelayDate[0]=RelayDate[0]|0x01;
                RelayDate[2]=RelayDate[2]|0x01;
                
            break;
            case FLOOR_10:
                RelayDate[0]=RelayDate[0]|0x02;
                RelayDate[2]=RelayDate[2]|0x02;
            break;
            case FLOOR_11:
                RelayDate[0]=RelayDate[0]|0x04;
                RelayDate[2]=RelayDate[2]|0x04;
            break;
            case FLOOR_12:
                RelayDate[0]=RelayDate[0]|0x08;
                RelayDate[2]=RelayDate[2]|0x08;
            break;
            case FLOOR_13:
                RelayDate[0]=RelayDate[0]|0x10;
                RelayDate[2]=RelayDate[2]|0x10;
            break;
            case FLOOR_14:
                RelayDate[0]=RelayDate[0]|0x20;
                RelayDate[2]=RelayDate[2]|0x20;
            break;
            case FLOOR_15:
                RelayDate[0]=RelayDate[0]|0x40;
                RelayDate[2]=RelayDate[2]|0x40;
            break;
            case FLOOR_16:
                RelayDate[0]=RelayDate[0]|0x80;
                RelayDate[2]=RelayDate[2]|0x80;
            break;
#endif
            default:
            break;
        }
        HC595_Send_Multi_Byte(RelayDate,4);
        // for(i=0;i<4;i++)
        //     PRINT("%02x ",RelayDate[i]);
        // PRINT("\r\n");
        return;
    }
    switch (iDate[0])
    {
        case FLOOR_1:
            Relay_Status[0]=0;
            RelayDate[1]=RelayDate[1]&0xFE;
            RelayDate[3]=RelayDate[3]|0x01;
        break;
        case FLOOR_2:
            Relay_Status[1]=0;
            RelayDate[1]=RelayDate[1]&0xFD;
            RelayDate[3]=RelayDate[3]|0x02;
        break;
        case FLOOR_3:
            Relay_Status[2]=0;
            RelayDate[1]=RelayDate[1]&0xFB;
            RelayDate[3]=RelayDate[3]|0x04;
        break;
        case FLOOR_4:
            Relay_Status[3]=0;
            PRINT("close 3\r\n");
            RelayDate[1]=RelayDate[1]&0xF7;
            RelayDate[3]=RelayDate[3]|0x08;
        break;
        case FLOOR_5:
            Relay_Status[4]=0;
            RelayDate[1]=RelayDate[1]&0xEF;
            RelayDate[3]=RelayDate[3]|0x10; 
        break;
        case FLOOR_6:
            Relay_Status[5]=0;
            RelayDate[1]=RelayDate[1]&0xDF;
            RelayDate[3]=RelayDate[3]|0x20; 
        break;
        case FLOOR_7:
            Relay_Status[6]=0;
            RelayDate[1]=RelayDate[1]&0xBF;
            RelayDate[3]=RelayDate[3]|0x40;
        break;
        case FLOOR_8:
            Relay_Status[7]=0;
            RelayDate[1]=RelayDate[1]&0x7F;//|0x80;
            RelayDate[3]=RelayDate[3]|0x80;
        break;
#ifdef LAYER_NUM_16
        case FLOOR_9:
            Relay_Status[8]=0;
            RelayDate[0]=RelayDate[0]&0xFE;
            RelayDate[2]=RelayDate[2]|0x01;
        break;
        case FLOOR_10:
            Relay_Status[9]=0;
            RelayDate[0]=RelayDate[0]&0xFD;
            RelayDate[2]=RelayDate[2]|0x02;
        break;
        case FLOOR_11:
            Relay_Status[10]=0;
            RelayDate[0]=RelayDate[0]&0xFB;
            RelayDate[2]=RelayDate[2]|0x04;
        break;
        case FLOOR_12:
            Relay_Status[11]=0;
            RelayDate[0]=RelayDate[0]&0xF7;
            RelayDate[2]=RelayDate[2]|0x08;
        break;
        case FLOOR_13:
            Relay_Status[12]=0;
            RelayDate[0]=RelayDate[0]&0xEF;
            RelayDate[2]=RelayDate[2]|0x10;
        break;
        case FLOOR_14:
            Relay_Status[13]=0;
            RelayDate[0]=RelayDate[0]&0xDF;
            RelayDate[2]=RelayDate[2]|0x20;
        break;
        case FLOOR_15:
            Relay_Status[14]=0;
            RelayDate[0]=RelayDate[0]&0xBF;
            RelayDate[2]=RelayDate[2]|0x40;
        break;
        case FLOOR_16:
            Relay_Status[15]=0;
            RelayDate[0]=RelayDate[0]&0x7F;
            RelayDate[2]=RelayDate[2]|0x80;
        break;
#endif
        default:
        break;
    }
    HC595_Send_Multi_Byte(RelayDate,4);
}


void SetDirectRelay_Date_Close(uint8_t *iDate)
{
    // uint8_t i=0;
    if(Get_Self_Count()!=0xFF)
    {
        switch (iDate[0])
        {
            case FLOOR_1:
                RelayDate[1]=RelayDate[1]|0x01;
                RelayDate[3]=RelayDate[3]|0x01;
            break;
            case FLOOR_2:
                RelayDate[1]=RelayDate[1]|0x02;
                RelayDate[3]=RelayDate[3]|0x02;
            break;
            case FLOOR_3:
                RelayDate[1]=RelayDate[1]|0x04;
                RelayDate[3]=RelayDate[3]|0x04;
            break;
            case FLOOR_4:
                RelayDate[1]=RelayDate[1]|0x08;
                RelayDate[3]=RelayDate[3]|0x08;
            break;
            case FLOOR_5:
                RelayDate[1]=RelayDate[1]|0x10;
                RelayDate[3]=RelayDate[3]|0x10; 
            break;
            case FLOOR_6:
                RelayDate[1]=RelayDate[1]|0x20;
                RelayDate[3]=RelayDate[3]|0x20;
                
            break;
            case FLOOR_7:
                RelayDate[1]=RelayDate[1]|0x40;
                RelayDate[3]=RelayDate[3]|0x40;
            break;
            case FLOOR_8:
                RelayDate[1]=RelayDate[1]|0x80;
                RelayDate[3]=RelayDate[3]|0x80;
                
            break;
    #ifdef LAYER_NUM_16
            case FLOOR_9:
                RelayDate[0]=RelayDate[0]|0x01;
                RelayDate[2]=RelayDate[2]|0x01;
                
            break;
            case FLOOR_10:
                RelayDate[0]=RelayDate[0]|0x02;
                RelayDate[2]=RelayDate[2]|0x02;
            break;
            case FLOOR_11:
                RelayDate[0]=RelayDate[0]|0x04;
                RelayDate[2]=RelayDate[2]|0x04;
            break;
            case FLOOR_12:
                RelayDate[0]=RelayDate[0]|0x08;
                RelayDate[2]=RelayDate[2]|0x08;
            break;
            case FLOOR_13:
                RelayDate[0]=RelayDate[0]|0x10;
                RelayDate[2]=RelayDate[2]|0x10;
            break;
            case FLOOR_14:
                RelayDate[0]=RelayDate[0]|0x20;
                RelayDate[2]=RelayDate[2]|0x20;
            break;
            case FLOOR_15:
                RelayDate[0]=RelayDate[0]|0x40;
                RelayDate[2]=RelayDate[2]|0x40;
            break;
            case FLOOR_16:
                RelayDate[0]=RelayDate[0]|0x80;
                RelayDate[2]=RelayDate[2]|0x80;
            break;
#endif
            default:
            break;
        }
        HC595_Send_Multi_Byte(RelayDate,4);
        // for(i=0;i<4;i++)
        //     PRINT("%02x ",RelayDate[i]);
        // PRINT("\r\n");
        return;
    }
    switch (iDate[0])
    {
        case FLOOR_1:
            RelayDate[1]=RelayDate[1]&0xFE;
            RelayDate[3]=RelayDate[3]&0xFE;
        break;
        case FLOOR_2:
            RelayDate[1]=RelayDate[1]&0xFD;
            RelayDate[3]=RelayDate[3]&0xFD;
        break;
        case FLOOR_3:
            RelayDate[1]=RelayDate[1]&0xFB;
            RelayDate[3]=RelayDate[3]&0xFB;
        break;
        case FLOOR_4:
            RelayDate[1]=RelayDate[1]&0xF7;
            RelayDate[3]=RelayDate[3]&0xF7;
        break;
        case FLOOR_5:
            RelayDate[1]=RelayDate[1]&0xEF;
            RelayDate[3]=RelayDate[3]&0xEF;
        break;
        case FLOOR_6:
            RelayDate[1]=RelayDate[1]&0xDF;
            RelayDate[3]=RelayDate[3]&0xDF;
        break;
        case FLOOR_7:
            RelayDate[1]=RelayDate[1]&0xBF;
            RelayDate[3]=RelayDate[3]&0xBF;
        break;
        case FLOOR_8:
            RelayDate[1]=RelayDate[1]&0x7F;//|0x80;
            RelayDate[3]=RelayDate[3]&0x7F;
        break;
#ifdef LAYER_NUM_16
        case FLOOR_9:
            RelayDate[0]=RelayDate[0]&0xFE;
            RelayDate[2]=RelayDate[2]&0xFE;
        break;
        case FLOOR_10:
            RelayDate[0]=RelayDate[0]&0xFD;
            RelayDate[2]=RelayDate[2]&0xFD;
        break;
        case FLOOR_11:
            RelayDate[0]=RelayDate[0]&0xFB;
            RelayDate[2]=RelayDate[2]&0xFB;
        break;
        case FLOOR_12:
            RelayDate[0]=RelayDate[0]&0xF7;
            RelayDate[2]=RelayDate[2]&0xF7;
        break;
        case FLOOR_13:
            RelayDate[0]=RelayDate[0]&0xEF;
            RelayDate[2]=RelayDate[2]&0xEF;
        break;
        case FLOOR_14:
            RelayDate[0]=RelayDate[0]&0xDF;
            RelayDate[2]=RelayDate[2]&0xDF;
        break;
        case FLOOR_15:
            RelayDate[0]=RelayDate[0]&0xBF;
            RelayDate[2]=RelayDate[2]&0xBF;
        break;
        case FLOOR_16:
            RelayDate[0]=RelayDate[0]&0x7F;
            RelayDate[2]=RelayDate[2]&0x7F;
        break;
#endif
        default:
        break;
    }
    HC595_Send_Multi_Byte(RelayDate,4);
}

void Set_All_Relay_Open(void)// void Set_All_Relay_Close(void)
{
    PRINT("all open\r\n");
    if(Get_Self_Count()!=0xFF)
    {
 #ifdef LAYER_NUM_16
        RelayDate[0]=0;
        RelayDate[2]=0;
 #endif
        RelayDate[1]=0;
        RelayDate[3]=0;
    }
    else 
    {
 #ifdef LAYER_NUM_16
        RelayDate[0]=0;
        RelayDate[2]=0;
 #endif
        RelayDate[1]=0;
        RelayDate[3]=0;    
    }
    HC595_Send_Multi_Byte(RelayDate,4);
}


void Set_All_Relay_Close(void)// void Set_All_Relay_Open(void)
{
    if(Get_Self_Count()!=0xFF)
    {
// #ifdef LAYER_NUM_16
        RelayDate[0]=0xFF;
        RelayDate[2]=0xFF;
// #endif
        RelayDate[1]=0xFF;
        RelayDate[3]=0xFF;
    }
    else 
    {
// #ifdef LAYER_NUM_16
        RelayDate[0]=0x00;
        RelayDate[2]=0xFF;
// #endif
        RelayDate[1]=0x00;
        RelayDate[3]=0xFF;
        memset(Relay_Status,0,16);
    }
    // RelayDate[0]=0xFF;
    // RelayDate[2]=0xFF;
    HC595_Send_Multi_Byte(RelayDate,4);
}


